-- item_per3floor
-- created by shuzy
-- 每前进2层迷宫，获得N个XX

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return 0;
        end

        -- 客户端此时还在前一层，需要+1计算
        local floor = DungeonM.currentLayer() + 1;

        -- 不是在3层，不处理
        if floor % 3 ~= 0 then
            return 0;
        end

        local classId;
        if "component_1" == prop[2] then
            classId = FormulaM.invoke("FETCH_PROP_RANDOM_BONUS", prop[2]);
        else
            classId = tonumber(prop[2]);
        end

        local count = tonumber(prop[3]);

        local bonus = {1, classId, count};
        BonusM.doBonus(bonus, "item_per3floor");

        return count;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local num = prop[3];
        local name = ItemM.query(prop[2], "name");
        local unit = ItemM.query(prop[2], "unit");

        -- 多种物品抽取某一种的，描述单独处理下
        if prop[2] == "component_1" then
            name = getLocStr("component");
            unit = ItemM.query(7522, "unit");
        end

        desc = string.gsub(desc, "{0}", name);
        desc = string.gsub(desc, "{1}", num);
        desc = string.gsub(desc, "{unit}", unit);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};